package interview.algortithm;

/**
 * @Author: zhangrongqing
 * @Date: 2020/5/16 10:24
 */
public class ReverseWord {

    public void reverseWord(String content){

        String[] str = content.split("\\s{1,}");

        for(int i = str.length - 1;i >= 0;i--){
            System.out.println(str[i]);
        }
    }

    public static void main(String[] args) {
        String content = "hello world zrq";
        String result = new String();

        char[] chars = content.toCharArray();

        //放中间结果，最长也就字符串长度
        char[] tmpChar = new char[chars.length];
        Integer tmpStart = 0;
        Integer tmpEnd = chars.length;
        for(int i = chars.length - 1;i >= 0 ;i--){
            char c = chars[i];
            if(c == ' '){
                String s = String.copyValueOf(chars, tmpStart, tmpEnd - tmpStart);
                System.out.println(s);
                tmpEnd = tmpStart;
            }else{
                tmpStart = i;
            }
        }
        if(tmpChar.toString() != null){
            System.out.println(String.copyValueOf(chars, tmpStart, tmpEnd - tmpStart));
        }
    }
}
